package com.lxmes.device.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.lxmes.device.domain.DeviceFailureRepair;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.device.domain.NcEmGzwx;
import com.lxmes.device.service.INcEmGzwxService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 设备故障维修Controller
 * 
 * @author ruoyi
 * @date 2023-02-11
 */
@RestController
@RequestMapping("/device/gzwx")
public class NcEmGzwxController extends BaseController
{
    @Autowired
    private INcEmGzwxService ncEmGzwxService;

    /**
     * 查询设备故障维修列表
     */
    @PreAuthorize("@ss.hasPermi('device:gzwx:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcEmGzwx ncEmGzwx)
    {
        startPage();
        List<NcEmGzwx> list = ncEmGzwxService.selectNcEmGzwxList(ncEmGzwx);
        return getDataTable(list);
    }

    //撤单
    @PostMapping(value = "/cancelReport/{reportId}")
    @PreAuthorize("@ss.hasPermi('device:gzwx:cancelReport')")
    public AjaxResult cancelReport(@PathVariable("reportId") String reportId)
    {
        return toAjax(ncEmGzwxService.cancelReport(reportId));
    }

    /**
     * 导出设备故障维修列表
     */
    @PreAuthorize("@ss.hasPermi('device:gzwx:export')")
    @Log(title = "设备故障维修", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcEmGzwx ncEmGzwx)
    {
        List<NcEmGzwx> list = ncEmGzwxService.selectNcEmGzwxList(ncEmGzwx);
        ExcelUtil<NcEmGzwx> util = new ExcelUtil<NcEmGzwx>(NcEmGzwx.class);
        util.exportExcel(response, list, "设备故障维修数据");
    }

    /**
     * 获取设备故障维修详细信息
     */
    @PreAuthorize("@ss.hasPermi('device:gzwx:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ncEmGzwxService.selectNcEmGzwxById(id));
    }

    /**
     * 新增设备故障维修
     */
    @PreAuthorize("@ss.hasPermi('device:gzwx:add')")
    @Log(title = "设备故障维修", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcEmGzwx ncEmGzwx)
    {
        return toAjax(ncEmGzwxService.insertNcEmGzwx(ncEmGzwx));
    }

    /**
     * 修改设备故障维修
     */
    @PreAuthorize("@ss.hasPermi('device:gzwx:edit')")
    @Log(title = "设备故障维修", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcEmGzwx ncEmGzwx)
    {
        return toAjax(ncEmGzwxService.updateNcEmGzwx(ncEmGzwx));
    }

    /**
     * 删除设备故障维修
     */
    @PreAuthorize("@ss.hasPermi('device:gzwx:remove')")
    @Log(title = "设备故障维修", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ncEmGzwxService.deleteNcEmGzwxByIds(ids));
    }

    /**
     * 新增设备故障报修单
     */
    @ApiOperation(value="添加故障维修操作")
    @Log(title = "设备故障维修单", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('mobile:repair:add')")
    @PostMapping("/apiAdd")
    public AjaxResult apiAdd(@RequestBody NcEmGzwx ncEmGzwx) throws Exception {
        return toAjax(ncEmGzwxService.updateApiDeviceFailureRepair(ncEmGzwx));
    }
    /**
     * API获取设备故障报修单详细信息
     */
    @ApiOperation(value="故障维修单详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reportId", value = "报修单号", required = true,paramType="path", dataType = "String", dataTypeClass = String.class),
    })
    @PreAuthorize("@ss.hasPermi('mobile:repair:info')")
    @GetMapping(value = "/getRepairInfo/{reportId}")
    public AjaxResult getRepairInfo(@PathVariable("reportId") String reportId)
    {
        return AjaxResult.success(ncEmGzwxService.selectDeviceFailureRepairByReportId(reportId));
    }
    /**
     * API撤单操作
     */
    @ApiOperation(value="故障维修撤单操作")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reportId", value = "报修单号", required = true,paramType="path", dataType = "String", dataTypeClass = String.class),
    })
    @PreAuthorize("@ss.hasPermi('mobile:repair:delete')")
    @PostMapping(value = "/apiCancelReport/{reportId}")
    public AjaxResult apiCancelReport(@PathVariable("reportId") String reportId)
    {
        return toAjax(ncEmGzwxService.cancelReport(reportId));
    }
}
